#include "graph.h"
#include <bits/stdc++.h>
using namespace std;

int ct;
int fa[210];
int du[210];
int vs[210][210];
int ds[210][210];
int dp[210][210];

inline int get(int x, int y) {
  while (y != 1) x /= 3, y--;
  return x % 3 + 1;
}
inline int gte(int x, int y) {
  x--;
  while (y != 1) x *= 3, y--;
  return x;
}
inline void dfs1(int x) {
  du[x] = NumberOfRoads();
  for (int i = 1; i <= du[x]; i++) {
    Move(i, 2);
    if (Color() == 2) {
      Move(LastRoad(), 2);
    } else {
      fa[++ct] = LastRoad();
      vs[x][i] = ct;
      dfs1(ct);
      Move(fa[vs[x][i]], 2);
    }
  }
}
inline void dfs2(int x, int y) {
  for (int i = 1; i <= du[x]; i++) {
    if (vs[x][i]) {
      Move(i, get(x, y));
      dfs2(vs[x][i], y);
      Move(fa[vs[x][i]], get(vs[x][i], y));
    }
  }
  for (int i = 1; i <= du[x]; i++) {
    if (!vs[x][i]) {
      Move(i, get(x, y));
      int c = Color();
      ds[x][i] += gte(c, y);
      Move(LastRoad(), c);
    }
  }
}

void Inspect(int R) {
  dfs1(ct = 1);
  dfs2(1, 1);
  dfs2(1, 2);
  dfs2(1, 3);
  dfs2(1, 4);
  dfs2(1, 5);
  memset(dp, 0x3f, sizeof dp);
  for (int i = 1; i <= ct; i++) {
    for (int j = 1; j <= du[i]; j++) {
      if (vs[i][j]) {
        dp[i][vs[i][j]] = 1;
      } else {
        dp[i][ds[i][j]] = 1;
      }
    }
    dp[i][i] = 0;
  }
  for (int k = 1; k <= ct; k++)
    for (int i = 1; i <= ct; i++)
      for (int j = 1; j <= ct; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
  vector<int> ns(R + 1);
  for (int i = 1; i <= ct; i++)
    for (int j = i + 1; j <= ct; j++)
      if (dp[i][j] <= R) ns[dp[i][j]]++;
  for (int i = 1; i <= R; i++)
    Answer(i, ns[i]);
}
